﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MediaPortal.GUI.Library;

namespace Burn4You
{
    public class DiskTypeSelectionScreen : GUIWindow
    {
        #region GUI Controls
        
        [SkinControlAttribute(20)]        protected GUIThumbnailPanel thumbPanelDiskType = null;

        [SkinControlAttribute(1)]        protected GUIButtonControl btnBack = null;

        #endregion

        #region Variables
        /// <summary>
        /// List of Types to show to the user.
        /// </summary>
        public static List<DiskType> DiskTypesToShow;
        /// <summary>
        /// The disk type chosen by the user.
        /// </summary>
        public static DiskType ChosenType;
        /// <summary>
        ///  This indicates if the users completed the window (by clicking on the next button). If false, ignore the disk type selected from this window.
        /// </summary>
        public static bool Completed = false;
        /// <summary>
        /// ID of the last window to call this screen.
        /// </summary>
        public static int CallingWindow;

        #endregion

        #region GUIWindow overrides

        public override bool Init()
        {

            return Load(GUIGraphicsContext.Skin + @"\Burn4YouDiskTypeSelectionScreen.xml");
        }

        protected override void OnPageLoad()
        {
            Utils.Burn4YouLog.Write("Disk Type Selection Screen: Loading Page");
            Completed = false;

            CallingWindow = GUIWindowManager.GetPreviousActiveWindow();

            FillDiskTypesGUIList();

            base.OnPageLoad();
        }

        public override int GetID
        {
            get
            {
                return 54265;
            }
        }

        protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType)
        {
            if (control == thumbPanelDiskType)
            {
                ChosenType = (DiskType)thumbPanelDiskType.SelectedListItem.TVTag;
                Completed = true;
                Utils.Burn4YouLog.Write("Disk Type Selection Screen: User completed screen.");
                GUIWindowManager.ShowPreviousWindow();
            }
            else if (control == btnBack)
            {
                Utils.Burn4YouLog.Write("Disk Type Selection Screen: User closed screen.");
                GUIWindowManager.ShowPreviousWindow();
            }

            base.OnClicked(controlId, control, actionType);
        }

        #endregion

        #region Functions

        private void FillDiskTypesGUIList()
        {
            thumbPanelDiskType.Clear();

            foreach (DiskType dtype in DiskTypesToShow)
            {
                GUIListItem item = new GUIListItem();
                item.Label = dtype.ToString();
                item.TVTag = dtype;

                thumbPanelDiskType.Add(item);
            }
        }

        #endregion
    }
}
